package com.gitee.wsl.mathematics.function.equation.ext

import com.gitee.wsl.mathematics.matrix.M
import com.gitee.wsl.mathematics.matrix.MutableMatrix


/**
 * 计算矩阵的秩，将破坏原矩阵
 */
fun<T:Number> MutableMatrix<T, *, *>.rankDestructive(): Int {
	rowEchelonAssign()
	return (colCount - 1 downTo 0).first { M[it].isNotZero }
}

/**
 * 计算矩阵的逆，将破坏原矩阵
 */
fun<T:Number> MutableMatrix<T, *, *>.inverseDestructive(unit:MutableMatrix<T, *, *>) = run {
	//val u = arrayMatrixOfUnit(dim)
	simplifyAssignWith(unit)
	if (lastRow.isNotZero) unit else null
}
